package com.morningstar.system.api.feign;

import cn.hutool.core.lang.UUID;
import com.morningstar.common.arco.SelectOption;
import com.morningstar.system.api.feign.fallback.SystemFormFeignFactory;
import feign.Logger;
import feign.RequestInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

import static com.morningstar.common.constants.feign.FeignClientConstants.SERVICE_SYSTEM;
import static com.morningstar.common.constants.feign.FeignUrlConstants.SYSTEM_FORM_SELECT;

@FeignClient(value = SERVICE_SYSTEM, configuration = ISystemFormFeign.Config.class, fallbackFactory = SystemFormFeignFactory.class)
public interface ISystemFormFeign {

    @GetMapping(SYSTEM_FORM_SELECT)
    List<SelectOption> select() throws Exception;


    class Config {

//        @Value("${feign.token}")
//        String feignToken;

        @Value("${spring.application.name}")
        String applicationName;

        @Bean
        Logger.Level feignLoggerLevel() {
            return Logger.Level.FULL;
        }

        @Bean
        RequestInterceptor interceptor() {
            return template -> {
                template.header("X-Request-Id", UUID.randomUUID().toString());
//                template.header("X-Signature", feignToken);
                template.header("X-Application-Name", applicationName);
            };
        }
    }
}
